/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.zumbits.avd;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;

/**
 *
 * @author zumbits
 */
public class Config {

    private static URL CONFIG_XML;
    private static SAXBuilder sax;
    private static Document xml;

    static {
        CONFIG_XML = new Config().getClass().getResource("/config.xml");
        sax = new SAXBuilder();
        try {
            xml = sax.build(CONFIG_XML);
        } catch (Exception ex) {
            Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /*public static String getUrlMysql() {
        List<Element> nodes = xml.getRootElement().getChildren("database");

        for (int i = 0; i < nodes.size(); i++) {
            List attributes = nodes.get(i).getAttributes();

            if (attributes.size() > 0
                    && ((Attribute) attributes.get(0)).getValue().equals("mysql")) {

                return ((Attribute) attributes.get(5)).getValue();
            }
        }

        return null;
    }*/

    public static List<String> getDataBaseMysql() {
        ArrayList<String> list = new ArrayList<String>();
        List<Element> nodes = xml.getRootElement().getChildren("database");

        for (int i = 0; i < nodes.size(); i++) {
            List attributes = nodes.get(i).getAttributes();

            if (attributes.size() > 0
                    && ((Attribute) attributes.get(0)).getValue().equals("mysql")) {

                for (int j = 1; j < attributes.size(); j++) {
                    list.add(((Attribute) attributes.get(j)).getValue());
                }
            }
        }

        return list;
    }

    public static List<String> getPathStorage() {
        List<Attribute> attributes = xml.getRootElement().getChild("storage").getAttributes();
        ArrayList<String> list = new ArrayList<String>();

        list.add(attributes.get(0).getValue());
        list.add(attributes.get(1).getValue());

        return list;
    }

    public static List<String> getPathLog() {
        List<Attribute> attributes = xml.getRootElement().getChild("log").getAttributes();
        ArrayList<String> list = new ArrayList<String>();

        list.add(attributes.get(0).getValue());
        list.add(attributes.get(1).getValue());

        return list;
    }
}
